package dao.hive;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
 
 public class Connect {
     private static Connection conn = null;
     private static Connection connToMysql = null;
 
     private Connect() {
     }
     
     //获得本地mysql连接  用于测试
     
     public static Connection GetMysqllocal() 
     {
    	 if (connToMysql == null) {
             try {
                 Class.forName("com.mysql.jdbc.Driver");
             } catch (ClassNotFoundException e) {
 
                 e.printStackTrace();
                 System.exit(1);
             }
             try {
				connToMysql = DriverManager.getConnection(
				         "jdbc:mysql://localhost:3306/log", "root", "root");
			} catch (SQLException e) {
				
				e.printStackTrace();
			}
         }
         return connToMysql;
     }
     
     // 获得hive连接
     public static Connection GetHiveConn() throws SQLException {
         if (conn == null) {
             try {
                 Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver");
             } catch (ClassNotFoundException e) {
 
                 e.printStackTrace();
                 System.exit(1);
             }
             conn = DriverManager.getConnection(
                     "jdbc:hive://192.168.88.25:10000/default", "hive", "123456");
         }
         return conn;
     }
     public static Connection GetMysqlConn() throws SQLException
     {
    	
             try {
                 Class.forName("com.mysql.jdbc.Driver");
             } catch (ClassNotFoundException e) {
 
                 e.printStackTrace();
                 System.exit(1);
             }
             conn = DriverManager.getConnection(
                     "jdbc:mysql://192.168.88.28:3306/log", "root", "root");
         
         return conn;
     }
     // 获得sql连接
     public static Connection getMySqlConn() throws SQLException {
         if (connToMysql == null) {
             try {
                 Class.forName("com.mysql.jdbc.Driver");
             } catch (ClassNotFoundException e) {
 
                 e.printStackTrace();
                 System.exit(1);
             }
             connToMysql = DriverManager.getConnection(
                     "jdbc:mysql://192.168.88.25:3306/hive", "hive", "123456");
         }
         return connToMysql;
     }
 
     public static void closeHive() throws SQLException {
         if (conn != null) {
             conn.close();
         }
     }
 
     public static void closeMysql() throws SQLException {
         if (connToMysql != null) {
             connToMysql.close();
         }
     }
 }